"""进度条模块"""

from PyQt5.QtWidgets import QProgressBar, QWidget, QVBoxLayout, QApplication
from PyQt5.QtCore import Qt

class ProgressBarWindow(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle('Progress Bar')
        layout = QVBoxLayout(self)
        self.pbar = QProgressBar(self)
        layout.addWidget(self.pbar)
        self.pbar.setValue(0)
        self.pbar.setMaximum(100)

    def set_title(self, title: str):
        """
        更改标题
        :param title: 标题
        :return:
        """
        self.setWindowTitle(title)

    def start_progress(self, max_value):
        """
        开始进度条
        :param max_value: 最大值
        :return:
        """
        self.pbar.setMaximum(max_value)
        self.pbar.setValue(0)

    def update_progress(self, value):
        """
        更新进度条
        :param value: 当前进度
        :return:
        """
        self.pbar.setValue(value)
        QApplication.processEvents()  # 更新GUI

    def close_progress_bar(self):
        """
        关闭进度条
        :return:None
        """
        self.pbar.hide()
        self.close()
